import { Bridge } from '@/utils';

const logout = async (response) => {
	await confirm(response.message);
	Bridge.getCtpTop().location.href = _ctxPath + '/main.do?method=logout';
};

/**
 * 后端：com.seeyon.ctp.login.CurrentUserToSeeyonApp
 */
const codeMapping = {
	/**
	 * 掉线
	 */
	1010: logout,
	/**
	 * 管理员踢人
	 */
	1003: logout,
	/**
	 * 管理员角色发生变化
	 */
	4011: logout
};


const getErrorHandler = (code) => {
	if (code === undefined || !(/^\d+$/).test(code)) {
		return null;
	}
	const handler = codeMapping[Number(code)];
	if (handler === undefined) {
		return null;
	}
	return handler;
};

export default {
	getHandler: getErrorHandler
};
